using System.Collections;
using Sirenix.OdinInspector;
using System.Collections.Generic;
using UnityEngine;
using Pangoo.Common;
using System;

namespace MetaTable
{
    [CreateAssetMenu(fileName = "MetaTableTemplate", menuName = "MetaTableTemplate")]
    public class MetaTableTemplate : ScriptableObject
    {
        [Serializable]
        public class MetaTableTemplateOverview
        {
            [ValueDropdown("OnNamespaceDropdown")]
            public string Namespace;



            [ValueDropdown("OnTableNameDropdown")]
            public string TableName;

            public string OverviewName => $"{TableName}Overview";

#if UNITY_EDITOR
            IEnumerable OnNamespaceDropdown()
            {
                ValueDropdownList<string> list = new ValueDropdownList<string>();
                var assets = AssetDatabaseUtility.FindAsset<MetaTableConfig>();
                foreach (var asset in assets)
                {
                    list.Add(asset.Namespace, asset.Namespace);
                }
                return list;
            }

            IEnumerable OnTableNameDropdown()
            {
                ValueDropdownList<string> ret = new ValueDropdownList<string>();
                var assets = AssetDatabaseUtility.FindAsset<MetaTableConfig>();
                foreach (var asset in assets)
                {
                    if (asset == null || asset.Namespace.IsNullOrWhiteSpace()) continue;
                    if (asset.Namespace.Equals(Namespace))
                    {
                        if (asset.Entries == null || asset.Entries.Count == 0) continue;
                        foreach (var entry in asset.Entries)
                        {
                            ret.Add(entry.BaseName);
                        }
                    }
                }
                return ret;

            }
#endif

        }

        public List<MetaTableTemplateOverview> Overviews;
    }

}
